package com.yiyi.util;

import java.util.ArrayList;
import java.util.List;

/**
 * 计算考试结果分数工具类
 *
 * @author yiyi
 * @date 2021/5/31
 */
public class CalculateGradeUtil {

    /**
     * 计算试卷中各选择题的分数
     *
     * @param userKey
     * @param realKey
     * @param choiceGrade
     * @return
     * */
    public static List<Integer> calculateChoice(List<String> userKey, List<String> realKey, List<Integer> choiceGrade) {
        List<Integer> gradeList = new ArrayList<>();
        for (int i = 0; i < userKey.size(); i++) {
            if (userKey.get(i).equals(realKey.get(i))) {
                gradeList.add(choiceGrade.get(i));
            } else {
                gradeList.add(0);
            }
        }
        return gradeList;
    }

    /**
     * 计算试卷总分
     *
     * @param choiceGrade
     * @param answerGrade
     * @return
     * */
    public static int calculateGrade(List<Integer> choiceGrade, List<Integer> answerGrade) {
        int sum = 0;
        for (Integer i : choiceGrade) {
            sum += i;
        }
        for (Integer i : answerGrade) {
            sum += i;
        }
        return sum;
    }
}
